﻿using System;
using System.Windows.Input;
using Action = System.Action;

namespace GaleSong
{
    /// <summary>
    ///     A menu part for various implementations of <see cref="IMenuPart" />.
    /// </summary>
    public class MenuPart : PartBase, IMenuPart, IObservableParent<IMenuPart>
    {
        private readonly IObservableCollection<IMenuPart> items = new BindableCollection<IMenuPart>();

        public MenuPart()
        {
        }

        public MenuPart(string name)
            : base(name)
        {
        }

        public MenuPart(string name, Action execute, Func<bool> canExecute = null)
            : base(name, execute, canExecute)
        {
        }

        public override void Execute()
        {
            //var statusBar = IoC.Get<ILogService>();
            //statusBar.ShowMessage("Execute " + DisplayName);
        }

        IObservableCollection<IMenuPart> IObservableParent<IMenuPart>.Items
        {
            get { return items; }
        }

        #region ISeparaterPart Members

        private bool _isSeparator;

        public bool IsSeparator
        {
            get { return _isSeparator; }
            protected set
            {
                _isSeparator = value;
                NotifyPropertyChanged(() => IsSeparator);
            }
        }

        #endregion

        #region IMenuPart Members

        private bool _isCheckable;

        private bool _isChecked;

        public bool IsCheckable
        {
            get { return _isCheckable; }
            set
            {
                _isCheckable = value;
                NotifyPropertyChanged(() => IsCheckable);
            }
        }

        public bool IsChecked
        {
            get { return _isChecked; }
            set
            {
                _isChecked = value;
                NotifyPropertyChanged(() => IsChecked);
            }
        }

        private KeyGesture _keyGesture;

        public KeyGesture KeyGesture
        {
            get { return _keyGesture; }
            set
            {
                _keyGesture = value;
                NotifyPropertyChanged(() => KeyGesture);
            }
        }

        #endregion
    }
}